package com.dqhl.business.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dqhl.business.R;
import com.dqhl.business.modle.Community;
import com.dqhl.business.util.Dlog;
import com.dqhl.business.util.ViewHolder;
import com.dqhl.business.view.CheckableLinearLayout;

import java.util.List;

/**
 * Created by guanluocang on 2016/11/8.
 */
public class CommunityAdapter extends BaseAdapter {

    private Context context;
    private List<Community> communiyList;
    private LayoutInflater inflater;
    private int selectItem = -1;
    private List<Community> communities;

    public CommunityAdapter(Context context, List<Community> communiyList) {
        this.communiyList = communiyList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }


    public CommunityAdapter(Context context, List<Community> communiyList, List<Community> communities) {
        this.communiyList = communiyList;
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.communities = communities;
    }

    @Override
    public int getCount() {
        return communiyList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.layout_community_item, viewGroup, false);
        }
        TextView tv_communityName = ViewHolder.get(view, R.id.tv_communityName);
        CheckableLinearLayout cll = ViewHolder.get(view, R.id.layout_community_item);

        Community community = communiyList.get(i);

        tv_communityName.setText(community.getName());

        if (community.isSelect()) {
            cll.setChecked(true);
        }


        return view;
    }
}
